home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / HPACK78S.ZIP / atari.c < prev    next >
C/C++ Source or Header  |  1992-12-03  |  5KB  |  191 lines

  1. /****************************************************************************
  2. *                                                                            *
  3. *                            HPACK Multi-System Archiver                        *
  4. *                            ===========================                        *
  5. *                                                                            *
  6. *                                 Atari-Specific Routines                        *
  7. *                             ATARI.C  Updated 26/09/92                        *
  8. *                                                                            *
  9. * This program is protected by copyright and as such any use or copying of    *
  10. *  this code for your own purposes directly or indirectly is highly uncool    *
  11. *                      and if you do so there will be....trubble.                *
  12. *                 And remember: We know where your kids go to school.            *
  13. *                                                                            *
  14. *            Copyright 1992  Peter C Gutmann.  All rights reserved            *
  15. *                                                                            *
  16. ****************************************************************************/
  17.  
  18. /* Note: This code predates the full Atari ST port - see the note in the
  19.          readme file for the full story */
  20.  
  21. #include <osbind.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <time.h>
  26. #include "defs.h"
  27. #include "frontend.h"
  28. #include "system.h"
  29. #include "io/hpackio.h"
  30. #include "io/fastio.h"
  31.  
  32. /* GemDOS <-> Unix date format conversion routines */
  33.  
  34. void unixToDos( LONG unixTime, WORD *dosTime, WORD *dosDate )
  35.     {
  36.     struct tm *tmtime;
  37.  
  38.     /* Break the Unix time into its component values */
  39.     tmtime = localtime( ( time_t * ) &unixTime );
  40.  
  41.     /* Build up the equivalent GemDOS values, with conversion for months
  42.        starting at 0 and years since 1980 */
  43.     *dosTime = ( tmtime->tm_sec >> 1 ) | ( tmtime->tm_min << 5 ) | \
  44.                ( tmtime->tm_hour << 11 );
  45.     *dosDate = ( tmtime->tm_mday ) | ( ( tmtime->tm_mon + 1 ) << 5 ) | \
  46.                ( ( tmtime->tm_year - 80 ) << 9 );
  47.     }
  48.  
  49. LONG dosToUnix( WORD dosDate, WORD dosTime )
  50.     {
  51.     struct tm timeBuf;
  52.  
  53.     /* Break up the GemDOS time into its component values, with conversion
  54.        for months starting at 0 and years since 1980 */
  55.     timeBuf.tm_sec = ( dosTime & 0x001F ) << 1;
  56.     timeBuf.tm_min = ( dosTime >> 5 ) & 0x003F;
  57.     timeBuf.tm_hour = ( dosTime >> 11 );
  58.     timeBuf.tm_mday = dosDate & 0x001F;
  59.     timeBuf.tm_mon = ( ( dosDate >> 5 ) & 0x000F ) - 1;
  60.     timeBuf.tm_year = ( dosDate >> 9 ) + 80;
  61.     timeBuf.tm_isdst = -1;                    /* Daylight saving indeterminate */
  62.     timeBuf.tm_wday = 0;
  63.     timeBuf.tm_yday = 0;
  64.  
  65.     return( mktime( &timeBuf ) );
  66.     }
  67.  
  68. /****************************************************************************
  69. *                                                                            *
  70. *                                SYSTEM Functions                            *
  71. *                                                                            *
  72. ****************************************************************************/
  73.  
  74. /* Set file time */
  75.  
  76. #define SETDATE        0
  77.  
  78. void setFileTime( const char *fileName, const LONG time )
  79.     {
  80.     FD theFD;
  81.     WORD dosDate, dosTime;
  82.     BYTE timeBuf[ 4 ];
  83.  
  84.     /* Convert Unix time to correct format for Ftimedat(), with the GemDOS
  85.        date in the first two bytes and the time in the second two bytes of a
  86.        buffer */
  87.     unixToDos( time, &dosDate, &dosTime );
  88.     mputWord( timeBuf, dosDate );
  89.     mputWord( timeBuf + 2, dosTime );
  90.  
  91.     /* Open the file and set its timestamp */
  92.     if( ( theFD = hopen( fileName, O_RDONLY ) ) == ERROR )
  93.         return;
  94.     Ftimedat( timeBuf, theFD, SETDATE );
  95.     hclose( theFD );
  96.     }
  97.  
  98. /* Find the first/next file in a directory.  This is simply a wrapper for
  99.    the standard findFirst/Next() call which un-dosifies the returned
  100.    information */
  101.  
  102. #if 0
  103. int findfirst (const char *pathname, struct dta *info, int attribute);
  104. int findnext (struct dta *info);
  105. struct dta {char attrib /* attribute found */
  106.             time_t time; /* date and time of file */
  107.             size_t length; /* length of file */
  108.             char filename[13];
  109.            };
  110. #endif /* 0 */
  111.  
  112. BOOLEAN findFirst( const char *filePath, const ATTR fileAttr, FILEINFO *fileInfo )
  113.     {
  114.     return( ( findfirst( filePath, ( struct dta * ) fileInfo, fileAttr ) != IO_ERROR ) ? TRUE : FALSE );
  115.     }
  116.  
  117. BOOLEAN findNext( FILEINFO *fileInfo )
  118.     {
  119.     return( ( findnext( ( struct dta * ) fileInfo ) != IO_ERROR ) ? TRUE : FALSE );
  120.     }
  121.  
  122. #if 0        /* May or may not need the following */
  123.  
  124. /* Case-insensitive string comparisons */
  125.  
  126. int strnicmp( const char *src, const char *dest, int length )
  127.     {
  128.     char srcCh, destCh;
  129.     char *srcPtr = (char *) src, *destPtr = (char *) dest;
  130.  
  131.     while( length-- )
  132.         {
  133.  
  134.         /* Need to be careful with toupper() side-effects */
  135.         srcCh = *srcPtr++;
  136.         srcCh = toupper( srcCh );
  137.         destCh = *destPtr++;
  138.         destCh = toupper( destCh );
  139.  
  140.         if( srcCh != destCh )
  141.             return( srcCh - destCh );
  142.         }
  143.  
  144.     return( 0 );
  145.     }
  146.  
  147. int stricmp( const char *src, const char *dest )
  148.     {
  149.     char srcCh, destCh;
  150.     char *srcPtr = (char *) src, *destPtr = (char *) dest;
  151.  
  152.     while( *srcPtr && *dest )
  153.         {
  154.         /* Need to be careful with toupper() side-effects */
  155.         srcCh = *srcPtr++;
  156.         srcCh = toupper( srcCh );
  157.         destCh = *destPtr++;
  158.         destCh = toupper( destCh );
  159.  
  160.         if( srcCh != destCh )
  161.             return( srcCh - destCh );
  162.         }
  163.  
  164.     return( 0 );
  165.     }
  166.  
  167. /* Lowercase a string */
  168.  
  169. void strlwr( char *string )
  170.     {
  171.     while( *string )
  172.         {
  173.         *string = tolower( *string );
  174.         string++;
  175.         }
  176.     }
  177. #endif /* 0 */
  178.  
  179. void getScreenSize( void )
  180.     {
  181.     /* Assume a model 33 for now - do something with getrez() ?? */
  182.     screenWidth  = 80;
  183.     screenHeight = 24;
  184.     }
  185.  
  186. int getCountry( void )
  187.     {
  188.     /* Default to US - there should be an XBIOS call to do it */
  189.     return( 0 );
  190.     }
  191.